package com.lsfb.signsys.view.BottomNavView;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.RestrictTo;
import android.support.v7.view.menu.MenuBuilder;
import android.support.v7.view.menu.MenuItemImpl;
import android.view.MenuItem;

import static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP;

/**
 * Created by zgscwjm on 2018/3/27.
 */

@RestrictTo(LIBRARY_GROUP)
public class BottomNavigationMenu extends MenuBuilder {

    public static final int MAX_ITEM_COUNT = 6;
    @SuppressLint("RestrictedApi")
    public BottomNavigationMenu(Context context) {
        super(context);
    }

    @SuppressLint("RestrictedApi")
    @Override
    protected MenuItem addInternal(int group, int id, int categoryOrder, CharSequence title) {
        if (size()+1>MAX_ITEM_COUNT){
            throw new IllegalArgumentException("菜单个数超过了");
        }


        //停止分发Item改变
        stopDispatchingItemsChanged();

        //添加itme
        final MenuItem item = super.addInternal(group, id, categoryOrder, title);

        if (item instanceof MenuItemImpl){
            //不知道干什么用的 -- 这个是设置 唯一可点击,类似于radio
            ((MenuItemImpl)item).setExclusiveCheckable(true);
        }

        //开启分发item改变
        startDispatchingItemsChanged();
        return item;
    }
}
